import * as types from "../types";

export default {
  state: {
    user: {},
    isLogin: false,
    token: null
  },
  mutations: {
    [types.LOGIN]: (state, data) => {
      sessionStorage.setItem("token", data.token);
      sessionStorage.setItem("menu", JSON.stringify(data.menus));
      state.token = data.token;
      state.isLogin = true;
      delete data.menus;
      sessionStorage.setItem("userInfo", JSON.stringify(data));
      state.user = data;
    },
    [types.LOGOUT]: state => {
      sessionStorage.clear();
      state.token = null;
      state.isLogin = false;
    }
  },
  actions: {
    userLogin({ commit }, data) {
      commit(types.LOGIN, data);
    }
  }
};
